package org.testtools.handler;

import java.util.Iterator;
import java.util.Map;

public class StringHandler {

    // TODO JUnit
    public static String replaceAllValues(String original, final Map<String, String> values) {
        final Iterator<Map.Entry<String, String>> iter = values.entrySet().iterator();
        Map.Entry<String, String> entry;

        while (iter.hasNext()) {
            entry = iter.next();
            original = original.replaceAll(escapeRegex(entry.getKey()), entry.getValue());
        }

        return original;
    }

    private static String escapeRegex(String str) {
        return str.replace("{", "\\{").replace("}", "\\}").replace("-", "\\-").replace("$", "\\$");
    }
}
